package com.wwwarehouse.resource_center.fragment.rules;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.Space;
import android.widget.TextView;

import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.resource_center.R;


/**
 * @author Joseph on 2017/8/15.
 *         <p/>
 *         编辑规则成功,新建规则成功共用界面，区分提示语
 *         无返回按钮
 */

public class ConfigurationSuccessFragment extends TheParentFragment implements View.OnClickListener {

    private Button mBtnComplete;
    private Button mBtnNext;
    private TextView mTvDescribe;
    private String success;
    private String businessId;
    private Space space;
    private String  title="";
    @Override
    protected int getContentId() {
        return R.layout.fragment_rule_success;
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof ConfigurationSuccessFragment)
            mActivity.setTitle(title);
    }

    @Override
    public void onSuccess(CommonClass commonClass, int i) {

    }

    @Override
    public void onReLoad(int code) {

    }

    @Override
    protected void init(View view) {
        mBtnComplete = findView(view, R.id.btn_complete);
        mBtnNext = findView(view, R.id.btn_new_next);
        mTvDescribe = findView(view, R.id.tv_describe);
        space = findView(view, R.id.space);
        mBtnNext.setText(R.string.config_new);
        mTvDescribe.setText(R.string.config_success);
        mBtnComplete.setOnClickListener(this);
        mBtnNext.setOnClickListener(this);
        ((BaseCardDeskActivity)mActivity).hideBackBt();
    }

    @Override
    protected void loadDatas() {
        Bundle arguments = getArguments();
        if (arguments != null) {
            success = arguments.getString("success");
            businessId = arguments.getString("businessId");
            if (TextUtils.equals("success", success)) {
                //新建规则成功
                title = getString(R.string.set_rules_name);
                mActivity.setTitle(title);
                mTvDescribe.setText(R.string.new_rule);
                mBtnNext.setText(R.string.new_next);
            } else if (TextUtils.equals("UPDATE", success)) {
                //编辑保存规则成功
                space.setVisibility(View.GONE);
                mBtnComplete.setVisibility(View.GONE);
                mBtnNext.setText(getString(R.string.complete));
                title = getString(R.string.edit_task_rule_suc);
                mActivity.setTitle(title);
                mTvDescribe.setText(R.string.update_success);
            } else if (TextUtils.equals("DELETE", success)) {
                //删除规则成功
                space.setVisibility(View.GONE);
                mBtnComplete.setVisibility(View.GONE);
                mBtnNext.setText(getString(R.string.complete));
                title  =  getString(R.string.edit_task_rule_suc);
                mActivity.setTitle(title);
                mTvDescribe.setText(R.string.delete_rule_success);
            }
        }
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.btn_complete) {
            if (TextUtils.isEmpty(success)) {
                //配置规则成功
                popFragment();
            } else if (TextUtils.equals("success", success)) {
                //新建规则成功
                popFragment();
            } else {
                popFragment();
            }

        } else if (i == R.id.btn_new_next) {
            if (TextUtils.isEmpty(success)) {
                //配置规则成功
                popFragment();
            } else if (TextUtils.equals("success", success)) {
                //新建规则成功
                popFragment();
                SetRulesFragment fragment = new SetRulesFragment();
                Bundle bundle = new Bundle();
                bundle.putString("businessId", businessId);
                fragment.setArguments(bundle);
                pushFragment(fragment);
            } else {
                popFragment();
            }

        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        ((BaseCardDeskActivity)mActivity).showBackBt();
    }
}
